Repository navigation
fix(bundle): read vite build output after buildApp resolves - #795
Merged
Merged
Conversation
On Vite 8, `builder.buildApp()` runs post-order `buildApp` hooks before the default environment builds when the config declares no `builder.buildApp`, so the hook resolved the build output while it was still undefined and `viteBuild` saw neither assets nor server bundle. Track each environment in `configResolved`, mark it built in `writeBundle`, and emit the output once every environment has finished. Fixes #792 Co-authored-by: Cursor <cursoragent@cursor.com>
Contributor
|
Install the packages built from this commit: alchemy bun add alchemy@https://pkg.ing/alchemy/08575b7@alchemy.run/better-auth bun add @alchemy.run/better-auth@https://pkg.ing/@alchemy.run/better-auth/08575b7@alchemy.run/pr-package bun add @alchemy.run/pr-package@https://pkg.ing/@alchemy.run/pr-package/08575b7 |
…ildApp Add the world's simplest Vite fixture (a client-only app, no config, no plugins) and a deploy test for it. Such a project resolves as `appType: "spa"`, so the Cloudflare Vite plugin declares no `builder.buildApp` and Vite falls back to the legacy single-environment builder — the exact code path from #792. That case also exposed that tracking "all registered environments built" never completes: the legacy builder only builds the `client` environment, so the registered `ssr` environment's `writeBundle` never fires. Drop the per-environment bookkeeping and instead read the collected output lazily; `viteBuild` already awaits `builder.buildApp()` before reading `output`, so every environment that actually built has run `writeBundle` by then. Co-authored-by: Cursor <cursoragent@cursor.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
On Vite 8,
builder.buildApp()runs post-orderbuildApphooks before the default environment builds when a project declares nobuilder.buildApp(e.g. a plain client-only SPA, which resolves asappType: "spa"). Ouralchemy:build-outputplugin resolved the build output from a post-orderbuildApphook, so it fired while the client/server output was still empty andviteBuilddied with "neither assets nor server output" (#792).viteBuildalready awaitsbuilder.buildApp()before readingoutput, so instead of resolving from a plugin hook, the plugin just collects state inwriteBundleand exposesoutputas a lazy read. By the timeviteBuildawaits it, every environment that actually built has runwriteBundle.return { plugin, - output: Deferred.await(deferred), + // Only safe to await *after* `builder.buildApp()` has resolved. + output: Effect.sync((): ViteBuildOutput => ({ + clientDirectory, + serverBundle: makeServerBundle(), + })), };This also avoids the trap of tracking "all registered environments built": a client-only SPA falls back to Vite's legacy single-environment builder, which only builds the
clientenvironment — the registeredssrenvironment never builds, so waiting on itswriteBundlewould hang forever.Test
Adds the world's simplest Vite fixture (
vite-spa-fixture: a client-only app, no config, no plugins) and a deploy test exercising theappType: "spa"path from #792.Fixes #792